//index

define("index",["jquery"],function($){
    var index={
        // 头部排 侧栏打开
        init:function(){

            //头部
            $(".hea-left li:not(:first-child)").on("click",function(){
                $(this).addClass("active").siblings().removeClass("active");
            });
            $(".hea-right li>span").on("click",function(e){
                e.stopPropagation();
                $(this).next().toggle();
            });
            $(document).on("click",function(){
                if($(".hea-div").css("display")=="block"){
                    $(".hea-right li>span").next().hide();
                }
            });
        //    侧边栏下拉
            $(".nav>li").on("click",".nav-span",function(){
                //e.preventDefault();
                $(this).toggleClass("span-xian").parent().siblings().find(".nav-span").removeClass("span-xian");
                $(this).next().slideToggle(200).parent().siblings().find(".nav-ul").slideUp(200);
                if($(this).next().css("display")=="none"){
                    //console.log("11");
                    $(this).removeClass("span-xian");
                }
            });
        //    侧边出现隐藏
            $(".ceshow").bind("click",function(){
                $(".nav").show();
                $(".content").addClass("content-two").css("position","relative");
            });
            $("#hea-close").bind("click",function(){
                $(".nav").toggle();
                $(".content").toggleClass("content-two");
                if($(".nav").css("display") == "block"){
                    $(".content").addClass("content-two").css("position","relative");
                } else {
                    $(".content").removeClass("content-two").css("position","static");
                }
            });
            //完事后隐藏
            if($(".nav").css("display") == "block"){
                $(".content").addClass("content-two").css("position","relative");
            } else {
                $(".content").removeClass("content-two").css("position","static");
            }
        },
        // 分类排 点击打开
        htmls:function(){
            var arr=["专题分类","专题管理","首页设计专用模板"];
            var obj=[
                {"htmlname":"oneHtml","cssname":"oneCss","jsname":"oneJs"},
                {"htmlname":"twoHtml","cssname":"twoCss","jsname":"twoJs"},
                {"htmlname":"threeHtml","cssname":"threeCss","jsname":"threeJs"}
            ];

            var num=-1;
            $(".zhuanti>li").each(function(index,item){
                var html=$(this).attr("htmlname");
                var css=$(this).attr("cssname");
                var js=$(this).attr("jsname");
                var flag;
                var con_poin=$(".con-position");
                var dt="<div class='title-dt' htmlname='"+obj[index].htmlname+"' cssname='"+obj[index].cssname+"' jsname='"+obj[index].jsname+"'><span>"+arr[index]+"</span><a>Χ</a></div>";
                $(item).on("click",function(){
                    num++;

                    // 延时开始加载
                    $(con_poin).show();
                    flag=false;
                    setTimeout(function(){
                        require(['requireText!'+html,'requireCss!'+css,js],function(html,css,js){
                            // 判断是否存在
                            function pan(){
                                $(con_poin).hide();
                                $(".con-bottom").html(html);
                                js.init();
                                $(".add-div").find(".title-dt").eq(index).find("span").addClass("title").parent().siblings().find("span").removeClass("title");
                                $(".add-div").siblings().removeClass("title");
                                return false;
                            }
                            if($(item).attr("htmlname") == $(".add-div").find(".title-dt").eq(0).attr("htmlname")){
                                pan();
                            }else if($(item).attr("htmlname") == $(".add-div").find(".title-dt").eq(1).attr("htmlname")){
                                pan();
                            }else if($(item).attr("htmlname") == $(".add-div").find(".title-dt").eq(2).attr("htmlname")){
                                pan();
                            }else{
                                //console.log("继续往下");
                                $(".con-bottom").html(html);
                                $(".con-l-dl .add-div").append(dt);
                                $(".add-div").find(".title-dt").eq(index).find("span").addClass("title").parent().siblings().find("span").removeClass("title");
                                $(".add-div").siblings().removeClass("title");
                                js.init();
                                $(con_poin).hide();
                            }
                            flag=true;

                        });

                    },700);
                });

            });

            $(".con-l-dl").on("click",".title-dt",function(e){
                e.stopPropagation();
                var html=$(this).attr("htmlname");
                var css=$(this).attr("cssname");
                var js=$(this).attr("jsname");
                $(this).find("span").addClass("title").parent().siblings().find("span").removeClass("title").parents(".add-div").siblings().removeClass("title");
                require(['requireText!'+html,'requireCss!'+css,js],function(html,css,js){
                    $(".con-bottom").html(html);
                    js.init();
                    //console.log(js.init(),111);
                });
            }).delegate("a","click",function(e){
                e.stopPropagation();
                $(this).parent().remove();
                $(".shouye").addClass("title").siblings().find("span").removeClass("title");
                $(".con-bottom").html(content);
            });
            var content=$(".con-bottom").html();
            $(".shouye").on("click",function(){
                $(this).addClass("title").siblings().find("span").removeClass("title");
                $(".con-bottom").html(content);
            });
        },
        // 横向排 关闭其他
        windows:function(){
            var content=$(".con-bottom").html();
            var num=0;
            $(".con-r-dl").on("click","dt",function(){
                $(this).next().toggle();
            }).on("click",".con-r-ol li",function(e){
                e.stopPropagation();
                if($(".add-div").find("div").find("span").hasClass("title")){
                    if(($(this).index()==0) && $(".add-div").find("span").hasClass("title")){
                        $(".add-div").find("div").find(".title").parent().remove();
                        $(".shouye").addClass("title");
                        $(".con-bottom").html(content);
                        $(this).parent().hide();
                    }else if(($(this).index()==1) && $(".add-div").find("div").find("span").hasClass("title")){
                        $(".add-div").find("div").remove();
                        $(".shouye").addClass("title");
                        $(".con-bottom").html(content);
                        $(this).parent().hide();
                    }else if(($(this).index()==2) && $(".add-div").find("div").find("span").hasClass("title")){
                        var con=$(".add-div").find("div").find(".title");
                        $(con).parent().siblings().remove();
                        //console.log(con);
                        $(this).parent().hide();
                    }
                }else{
                    $(this).parent().hide();
                }
            });
            $(".con-top-r").on("click","p:nth-of-type(1)",function(){
                //history.go(0);
                //window.location.reload();
                $(".links").attr("href","images/timg.gif");
                setTimeout(function(){
                    $(".links").attr("href","//s1.tthunbohui.cn/static/favicon.ico");
                    history.go(0);
                },500);

            }).on("click","p:nth-of-type(2)",function(){
                num++;
                if(num===1){
                    //这里必须是DOM元素
                    var elem = document.getElementsByTagName("body")[0];
                    requestFullScreen(elem);
                    $(this).text("退出");
                    localStorage.setItem("kkk","qqqq");
                }else if(num===2){
                    exitFull();
                    num=0;
                    $(this).text("全屏");
                }
            });
            // 开启全屏
            function requestFullScreen(element) {
                // 判断各种浏览器，找到正确的方法
                var requestMethod = element.requestFullScreen || //W3C
                    element.webkitRequestFullScreen ||    //Chrome等
                    element.mozRequestFullScreen || //FireFox
                    element.msRequestFullScreen; //IE11
                if (requestMethod) {
                    requestMethod.call(element);
                }
                else if (typeof window.ActiveXObject !== "undefined") {
                    var wscript = new ActiveXObject("WScript.Shell");
                    if (wscript !== null) {
                        wscript.SendKeys("{F11}");
                    }
                }
            }
            //退出全屏 判断浏览器种类
            function exitFull() {
                // 判断各种浏览器，找到正确的方法
                var exitMethod = document.exitFullscreen || //W3C
                    document.mozCancelFullScreen ||    //Chrome等
                    document.webkitExitFullscreen || //FireFox
                    document.webkitExitFullscreen; //IE11
                if (exitMethod) {
                    exitMethod.call(document);
                }
                else if (typeof window.ActiveXObject !== "undefined") {//for Internet Explorer
                    var wscript = new ActiveXObject("WScript.Shell");
                    if (wscript !== null) {
                        wscript.SendKeys("{F11}");
                    }
                }
            }
        },
        local:function(){
            $(".hea-right .hea-div").on("click","span:first-child",function(){
                localStorage.clear();
                setTimeout(function(){
                    alert("清楚缓存成功")
                },500);
            }).on("click","span:last-child",function(){
                var con=confirm("客官，你确定要退出？"); //在页面上弹出对话框
                if(con==true){
                    window.location.href="login.html";
                }
            });
        //    后台时间
            var num="0";
        //    var str=''+ num;
        //    function fun(){
        //        str.length==2?return true:return false;
        //        num>10?return true:return false;
        //        num<99?return false:return fun();
        //    }
            setInterval(function(){
                var time=new Date();
                var full=time.getFullYear();
                var month=time.getMonth()+1;
                var date=time.getDate();
                var hour=time.getHours();
                var minute=time.getMinutes();
                var second=time.getSeconds();
                var months=(month<=9)?num+month:month;
                var dates=(date<=9)?num+date:date;
                var hours=(hour<=9)?num+hour:hour;
                var minutes=(minute<=9)?num+minute:minute;
                var seconds=(second<=9)?num+second:second;
                //console.log(months,dates,hours,minutes,seconds);
                $(".o-bottomul p:nth-child(2)").text("Server time："+full+"/"+months+"/"+dates+","+hours+":"+minutes+":"+seconds+"")
            },1000);

        },
        inputs:function(){
            $(document).on("click","#zhuanhuan_one,#zhuanhuan_two",function(){
                //var reg2=/^http:\/\/([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?$/gi;
                var reg=/^(http[s]?:)?(\/{2})?([a-z0-]+\.)?[a-z0-9]+(\.(com|cn|cc|org|net|com.cn))$/gi;
                var sty={background: "none",padding: "0 0 0 20px",color:"#c40000"};
                var val=$(this).prev().val();
                console.log(typeof reg);
                if($(this).prev().val() !== ""){
                    if(reg.test(val)){
                        var str="http://t.cn/REScaHX";
                        let li="<dd><s style='font-size: 12px;'>转换成功</s><a href='"+val+"'>"+str+"</a></dd>";
                        $(li).find("a").css(sty);
                        $(".input-app-one").append(li);
                        console.log($(li).css(sty));
                    }else{
                        console.log("不对");
                        $(".xinlang").show().find("p").text("请输入正确的URL");
                    }
                }else{
                    console.log("显示弹窗");
                    $(".xinlang").show();
                }
            });
            $(".xinlang-close").on("click",function(){
                $(this).parents(".xinlang").hide();
            })
        },
        denglu:function(){
            if(sessionStorage.getItem("zhusir")){
                $(".hea-right li > span").text(sessionStorage.getItem("zhusir"));
            }else{
                alert("你还未登录，请先登录");
                window.location.href="login.html";
            }

        }

    };
    return index;

});









